﻿#define _CRT_SECURE_NO_WARNINGS
#include "tou.h"


void A1(char arr[ROWS][COLS], int rows, int cols, char set)
{
	for (int a = 0; a < rows; a++)
	{
		for (int b = 0; b < cols; b++)
		{
			arr[a][b] = set;
		}
	}
}


void A2(char arr[ROWS][COLS], int row, int col)
{
	printf("------扫雷游戏-----\n");
	for (int c = 0; c <= col; c++)
	{
		printf("%d ",c);//打印列序号
	}
	printf("\n");
	for (int a = 1; a <= row; a++)
	{
		printf("%d ", a);//打印行序号
		for (int b = 1; b <= col; b++)
		{
			printf("%c ", arr[a][b]);
		}
		printf("\n");
	}

}

void A3(char arr[ROWS][COLS], int row, int col)
{
	int a = LEI;
	while (a)
	{
		int b = rand() % row + 1;
		int c = rand() % col + 1;
		if (arr[b][c] == '0')
		{
			arr[b][c] = '1';
			//printf("arr1[%d][%d]=%c\n",b,c, arr[b][c]);
			a--;
		}
	}
}

static int A5(char arr1[ROW][COLS],int x,int y)
{

	return (arr1[x - 1][y - 1] + arr1[x - 1][y] + arr1[x - 1][y + 1] + arr1[x][y - 1]
		+ arr1[x][y + 1] + arr1[x + 1][y - 1] + arr1[x + 1][y] + arr1[x + 1][y + 1] - 8 * '0');
}

void A4(char arr1[ROWS][COLS], char arr2[ROWS][COLS], int row, int col)
{
	int x = 0;
	int y = 0;
	int a = 0;
	
	while (a<(row*col)-LEI)
	{
		printf("请输入要排查的坐标:>");
		scanf("%d%d", &x, &y);
		if ((x <= row && x > 0) && (y <= col && y>0))
		{
			if (arr1[x][y] == '1')
			{
				printf("很遗憾,你被雷炸死!\n");
				Sleep(3000);
				A2(arr1, row, col);
				Sleep(3
					(3000);
				break;
			}
			else if (arr2[x][y] != '*')
				printf("改位置已经排查过\n");

			else
			{
				system("cls");
				int c= A5(arr1,x, y);
				arr2[x][y] = c + '0';
				A2(arr2, row, col);
				a++;
			}

		}
		else
		{
			printf("坐标非法，重新输入\n"); 
		}

	}
	if (a == (row * col) - LEI)
	{
		printf("恭喜你，排雷成功！\n");
		A2(arr2, ROW, COL);
	}
}
